package com.victor.utils;

import java.util.HashMap;
import java.util.Map;

public class Msg {
	private int code;
	private String msg;
	private String error;
	private Map<String, Object> extend = new HashMap<String, Object>();

	public String getError() {
		return error;
	}

	public void setError(String error) {
		this.error = error;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Map<String, Object> getExtend() {
		return extend;
	}

	public void setExtend(Map<String, Object> extend) {
		this.extend = extend;
	}

	public Msg add(String key, Object value) {
		this.getExtend().put(key, value);
		return this;

	}

	public static Msg success() {
		Msg result = new Msg();
		result.setCode(100);
		result.setMsg("成功");
		return result;
	}

	public static Msg fail() {
		Msg result = new Msg();
		result.setCode(200);
		result.setMsg("失败");
		result.setError("未知错误");
		return result;
	}

	public static Msg fail(String error) {
		Msg result = new Msg();
		result.setCode(200);
		result.setMsg("失败");
		result.setError(error);
		return result;
	}
	
	public static Msg judge(boolean bool) {
		if (bool) {
			return Msg.success();
		} else {
			return Msg.fail();
		}
	}
	
	public Msg result(Map<String, Object> param) {
		extend = param;
		return this;
	}

}
